﻿using System;
using System.Collections.Generic;
using System.Linq;
using Synology.AudioStationApi;

namespace PartTwo
{
    public class SearchService : ISearchService
    {
        private readonly ISearchResultViewModelFactory _searchResultViewModelFactory;
        private readonly AudioStationSession _audioStationSession;

        public SearchService(AudioStationSession audioStationSession, ISearchResultViewModelFactory searchResultViewModelFactory)
        {
            _searchResultViewModelFactory = searchResultViewModelFactory;
            _audioStationSession = audioStationSession;
        }

        public IEnumerable<ISearchResultViewModel> Search(string searchQuery)
        {
            var results = _audioStationSession.RequestHamilcarServeftpCom5000BrowseCgi(searchQuery).Select(o => _searchResultViewModelFactory.Create(o));
            return results;
        }
    }
}